package com.zztl.infiniteBand.ui.activity

import android.graphics.Color
import android.text.TextUtils
import android.view.View
import butterknife.OnClick
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.base.BaseMvpActivity
import com.zztl.infiniteBand.model.AuditStatusBean
import com.zztl.infiniteBand.presenter.AuditSuccessOrFailPresenter
import com.zztl.infiniteBand.ui.view.mvpview.CertificationInfoView
import com.zztl.infiniteBand.util.DateUtils
import kotlinx.android.synthetic.main.activity_audit_success_or_fail.*
import java.util.*

class AuditSuccessOrFailActivity : BaseMvpActivity<CertificationInfoView,AuditSuccessOrFailPresenter>(), CertificationInfoView {
  /*  @BindView(R.id.linearLayout)
     lateinit var linearLayout: LinearLayout
    @BindView(R.id.iv_first)
    lateinit var iv_first: ImageView
    @BindView(R.id.tv_status)
    lateinit var tv_status: TextView
    @BindView(R.id.iv_seconde)
    lateinit var iv_seconde: ImageView
    @BindView(R.id.tv_fail)
    lateinit var tv_fail: TextView
    @BindView(R.id.ll_success)
    lateinit var ll_success: LinearLayout
    @BindView(R.id.item_name)
    lateinit var mLlname: CommonItemView
    @BindView(R.id.item_type)
    lateinit  var item_type: CommonItemView
    @BindView(R.id.item_number)
    lateinit var item_number: CommonItemView
    @BindView(R.id.item_date)
    lateinit var item_date: CommonItemView
    @BindView(R.id.btn_resubmit)
    lateinit var btn_resubmit: Button
    @BindView(R.id.tv_reason)
    lateinit  var tv_reason: TextView
*/

    lateinit var mPresenter: AuditSuccessOrFailPresenter

    override fun setLayoutId(): Int =R.layout.activity_audit_success_or_fail


    override fun initBase() {
        headerView!!.setBackgroundColor(Color.TRANSPARENT)
        setTitle(getString(R.string.实名认证))
        mPresenter.getAuditInfo(this)
    }

    override fun createPresenter(): AuditSuccessOrFailPresenter {
        mPresenter = AuditSuccessOrFailPresenter()
        return mPresenter
    }


    override fun success(bean: AuditStatusBean) {
        linearLayout.visibility = View.VISIBLE
        setUiByStatus(bean)
    }

    private fun setUiByStatus(bean: AuditStatusBean) {
        //审核成功
        if ("2" == bean.data!!.auditState) {
            iv_first.setImageResource(R.mipmap.oval)
            iv_seconde.setImageResource(R.mipmap.oval)
            tv_status.text = getString(R.string.认证通过)
            tv_status.setTextColor(Color.parseColor("#3785FF"))
            tv_reason.text = getString(R.string.您的身份信息)
            tv_fail.visibility = View.GONE
            ll_success.visibility = View.VISIBLE

            btn_resubmit.visibility = View.GONE
            item_name.setMiddleTextStr(bean.data!!.realName!!)
            when (bean.data!!.idType) {
                "1" -> item_type.setMiddleTextStr(getString(R.string.身份证1))
                "2" -> item_type.setMiddleTextStr(getString(R.string.护照))
                "3" -> item_type.setMiddleTextStr(getString(R.string.港澳通行证))
                "4" -> item_type.setMiddleTextStr(getString(R.string.回乡证))
                "0" -> item_type.setMiddleTextStr(getString(R.string.其他))
            }

            item_number.setMiddleTextStr(bean.data!!.idNumber!!)
            val certificateTime = bean.data!!.certificateTime
            if (!TextUtils.isEmpty(certificateTime)) {
                item_date.setMiddleTextStr(DateUtils.formatTime(Date(java.lang.Long.parseLong(certificateTime))))
            }
        } else if ("3" == bean.data!!.auditState) {
            iv_first.setImageResource(R.mipmap.oval2)
            iv_seconde.setImageResource(R.mipmap.oval2)
            tv_status.text = getString(R.string.认证失败)
            tv_status.setTextColor(Color.parseColor("#FF2E63"))
            tv_reason.text = getString(R.string.认证失败原因)
            tv_fail.visibility = View.VISIBLE
            ll_success.visibility = View.GONE
            btn_resubmit.visibility = View.VISIBLE
            tv_fail.text = bean.data!!.failureMessage
        }
    }

    @OnClick(R.id.btn_back, R.id.btn_resubmit)
    fun click(view: View) {
        when (view.id) {
            R.id.btn_back -> finish()
            R.id.btn_resubmit -> skipActivity(this, CertificationActivity::class.java)
        }
    }
}
